package com.y.architecture.base_refresh_load;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;

import com.y.architecture.R;
import com.y.architecture.base_refresh.BaseRefreshHelper;
import com.y.architecture.item_decoretion.HorizontalDividerItemDecoration;
import com.y.architecture.recycle_util.BaseQuickAdapter;
import com.y.architecture.recycle_util.BaseViewHolder;

/**
 * Created by youjingjing on 2017/11/28.
 */

public class BaseRefreshLoadHelper<T> extends BaseRefreshHelper<IBaseRefreshLoadContact.IBaseRefreshLoadView<T>> implements IBaseRefreshLoadContact.IBaseRefreshLoadPresenter<T> {

    private RecyclerView mRecyclerView;

    public BaseRefreshLoadHelper(IBaseRefreshLoadContact.IBaseRefreshLoadView<T> mBaseView) {
        super(mBaseView);
    }

    public BaseRefreshLoadHelper(IBaseRefreshLoadContact.IBaseRefreshLoadView<T> mBaseView, View mRoot) {
        super(mBaseView, mRoot);
    }

    @Override
    public RecyclerView initRecycleView() {
        mRecyclerView =  getView(R.id.pre_recycler_view);
        return mRecyclerView;
    }

    @Override
    public RecyclerView.LayoutManager setDefaultLayoutManager() {
        return new LinearLayoutManager(mBaseView.getAFContext());
    }

    @Override
    public BaseQuickAdapter<T, BaseViewHolder> setAdapter() {
        BaseQuickAdapter<T, BaseViewHolder> mAdapter = mBaseView.getAdapter();
        mAdapter.setEmptyView(setEmptyView());
        mAdapter.setOnLoadMoreListener(mBaseView, mRecyclerView);
        mAdapter.setOnItemClickListener(mBaseView);
        return mAdapter;
    }

    @Override
    public View setEmptyView() {
        View emptyView = LayoutInflater.from(mBaseView.getAFContext()).inflate(R.layout.af_layout_empty, mRecyclerView, false);
        emptyView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mBaseView.onEmptyViewClicked(v);
            }
        });
        return emptyView;
    }

    @Override
    public void addDivider() {
        if (mBaseView.isShowDivider()) {
            mRecyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(mBaseView.getAFContext())
                    .color(mBaseView.getAFContext().getResources().getColor(R.color.black_divider))
                    .sizeResId(R.dimen.spacing_divider)
                    .build());
        }
    }

    //    @Override
//    public void onLoadBegin(SpinKitView frame) {
//        mBaseView.autoLoad();
//        mCurrPage = AFConstant.REFRESH_FIRST_PAGE;
//
//        mBaseView.loadData(mCurrPage);
//    }


}
